package com.example.springboot_jap_model.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * 拦截器
 */
@Configuration
public class WebAppConfig implements WebMvcConfigurer {


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> stringList = new ArrayList<>();
        //静态资源
        stringList.add("/js/**");
        stringList.add("/css/**");
        stringList.add("/fonts/**");
        stringList.add("/images/**");
        stringList.add("/sass/**");
        stringList.add("/assets/**");

        List<String> urlList = new ArrayList<>();
        urlList.add("/login");
        urlList.add("/user/doLogin");
        urlList.add("/user/logOut");
        urlList.add("/user/addUser");
        //注册自定义拦截器，添加拦截路径和排除拦截路径
        registry.addInterceptor(new InterceptorConfig())
                //排除拦截的请求
                .excludePathPatterns(stringList)//静态资源拦截
                .excludePathPatterns(urlList)//页面拦截
                //拦截 所有的请求
                .addPathPatterns("/**")
        ;
    }
}
